﻿using DataMgr.mode;
using DataMgr.msg.req;
using DataMgr.msg.rsp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DataMgr.CapSel
{
    /// <summary>
    /// 分容相关业务
    /// </summary>
    class CapSelMgr
    {
        //private static MyDb m_myDb = new MyDb();
        public static RspCapSelValue  QueryCapSel(string strReq)
        {
            ReqCapSelValue req = new ReqCapSelValue();
            req.Parse(strReq);
            //CapSelType type = req.capSelType;
            RspCapSelValue rsp = new RspCapSelValue();
            rsp.capSelType = req.capSelType;
            foreach (ArrayListMsg item in req.testList)
            {
                UInt32 testId = UInt32.Parse(item[0].ToString());
                UInt32 chlNo = UInt32.Parse(item[1].ToString());
                ArrayListMsg alm = new ArrayListMsg();
                alm.Add(item[0]);
                alm.Add(item[1]);
                //alm.Add(QueryTestCapacityValue(req.devNo, testId, chlNo, ArrayListMsg alm, req.stepNo,));
                QueryTestCapacityValue(req.devNo, testId, chlNo, req.stepNo, req.capSelType, alm);
                rsp.result.Add(alm);
            }

            return rsp;
        }

        private static void QueryTestCapacityValue(int devNo, UInt32 testId, 
            UInt32 chlNo,  int stepNo, int capType, ArrayListMsg alm)
        {
            MyDb myDb = new MyDb();
            myDb.Init();
            List<string> listResult = myDb.QueryStepEndValue(devNo, testId, chlNo, stepNo, capType);
            if (listResult.Count != 5)
            {
                foreach (var item in listResult)
                {
                    alm.Add(item);
                }
            }
            //else
            //    for (int i = 0; i < 5; i++)
            //    {
            //        alm.Add("");
            //    }

            listResult = myDb.QueryStepBeginValue(devNo, testId, chlNo, stepNo, capType);
            if (listResult.Count != 1)
            {
                foreach (var item in listResult)
                {
                    alm.Add(item);
                }
            }
            else
                alm.Add("");
        }
    }
}
